<?php

class sitesystem extends spController
{

    function __construct()
    {
        // 一些操作
        include("lib/language.php");
        parent::__construct();
        if (empty($_SESSION['xiaoq']['username'])) {
            $this->error('您还没登录！', spUrl("main", "index"));
        }
    }

    //默认首页
    function index()
    {
        $condition = array('id' => 1);
        $systemdetail = spClass('site_system')->find($condition);
        $this->systemdetail = $systemdetail;
        $this->display('aj/sitesystem.html');
    }

    //修改数据
    function update()
    {
        $id = empty($_REQUEST['id']) ? $this->error('程序出现错误！') : $_REQUEST['id'];
        $title = empty($_POST['title']) ? "" : $_POST['title'];
        $keywords = empty($_POST['keywords']) ? "" : $_POST['keywords'];
        $description = empty($_POST['description']) ? "" : $_POST['description'];
        $entitle = empty($_POST['entitle']) ? "" : $_POST['entitle'];
        $enkeywords = empty($_POST['enkeywords']) ? "" : $_POST['enkeywords'];
        $endescription = empty($_POST['endescription']) ? "" : $_POST['endescription'];
        $tel = empty($_POST['tel']) ? "" : $_POST['tel'];
        $fax = empty($_POST['fax']) ? "" : $_POST['fax'];
        $address = empty($_POST['address']) ? "" : $_POST['address'];
        $enaddress = empty($_POST['enaddress']) ? "" : $_POST['enaddress'];
        $skeyword = empty($_POST['skeyword']) ? "" : $_POST['skeyword'];
        $lxman = empty($_POST['lxman']) ? "" : $_POST['lxman'];
        $enlxman = empty($_POST['enlxman']) ? "" : $_POST['enlxman'];
        $phone = empty($_POST['phone']) ? "" : $_POST['phone'];
        $wurl = empty($_POST['wurl']) ? "" : $_POST['wurl'];
        $company = empty($_POST['company']) ? "" : $_POST['company'];
        $encompany = empty($_POST['encompany']) ? "" : $_POST['encompany'];
        $email = empty($_POST['email']) ? "" : $_POST['email'];

        $qq1 = empty($_POST['qq1']) ? "" : $_POST['qq1'];

        $qq2 = empty($_POST['qq2']) ? "" : $_POST['qq2'];

        $qq3 = empty($_POST['qq3']) ? "" : $_POST['qq3'];

        $qq4 = empty($_POST['qq4']) ? "" : $_POST['qq4'];

        $updaterow = array(
            'title' => $title,
            'keywords' => $keywords,
            'description' => $description,
            'entitle' => $entitle,
            'enkeywords' => $enkeywords,
            'endescription' => $endescription,
            'tel' => $tel,
            'fax' => $fax,
            'address' => $address,
            'enaddress' => $enaddress,
            'skeyword' => $skeyword,
            'lxman' => $lxman,
            'enlxman' => $enlxman,
            'phone' => $phone,
            'wurl' => $wurl,
            'company' => $company,
            'encompany' => $encompany,
            'email' => $email,
            'qq1' => $qq1,
            'qq2' => $qq2,
            'qq3' => $qq3,
            'qq4' => $qq4,
        );
        //var_dump($updaterow);
        //exit();
        $condition = array('id' => $id);
        $row = spClass('site_system')->update($condition, $updaterow);
        if ($row) {
            $link[0]['text'] = '返回修改页面';
            $link[0]['href'] = spUrl("sitesystem", "index");
            $this->sys_msg("修改成功！", 0, $link);
        }
    }

    /**
     * 系统提示信息
     */
    function sys_msg($msg_detail, $msg_type = 0, $links = array(), $auto_redirect = true)
    {
        if (count($links) == 0) {
            $links[0]['text'] = '返回';
            $links[0]['href'] = 'javascript:history.go(-1)';
        }
        $this->msg_detail = $msg_detail;
        $this->msg_type = $msg_type;
        $this->links = $links;
        $this->default_url = $links[0]['href'];
        $this->auto_redirect = $auto_redirect;
        $this->display('aj/message.html');
    }


    /**
     * 获得设置信息
     *
     * @param   array $groups 需要获得的设置组
     * @param   array $excludes 不需要获得的设置组
     *
     * @return  array
     */
// function get_settings($groups=null, $excludes=null)
// {
    // global $db, $ecs, $_LANG;

    // $config_groups = '';
    // $excludes_groups = '';

    // if (!empty($groups))
    // {
    // foreach ($groups AS $key=>$val)
    // {
    // $config_groups .= " AND (id='$val' OR parent_id='$val')";
    // }
    // }

    // if (!empty($excludes))
    // {
    // foreach ($excludes AS $key=>$val)
    // {
    // $excludes_groups .= " AND (parent_id<>'$val' AND id<>'$val')";
    // }
    // }

    // /* 取出全部数据：分组和变量 */
    // $sql = "SELECT * FROM sp_config WHERE type<>'hidden' $config_groups $excludes_groups ORDER BY parent_id, sort_order, id";
    // $item_list = spClass('site_config')->findSql($sql);

    // /* 整理数据 */
    // $group_list = array();
    // foreach ($item_list AS $key => $item)
    // {
    // $pid = $item['parent_id'];
    // $item['name'] = isset($item['description']) ? $item['description'] : $item['code'];
    // $item['desc'] = isset($_LANG['cfg_desc'][$item['code']]) ? $_LANG['cfg_desc'][$item['code']] : '';

    // if ($item['code'] == 'sms_shop_mobile')
    // {
    // $item['url'] = 1;
    // }
    // if ($pid == 0)
    // {
    // /* 分组 */
    // if ($item['type'] == 'group')
    // {
    // $group_list[$item['id']] = $item;
    // }
    // }
    // else
    // {
    // /* 变量 */
    // if (isset($group_list[$pid]))
    // {
    // if ($item['store_range'])
    // {
    // $item['store_options'] = explode(',', $item['store_range']);

    // foreach ($item['store_options'] AS $k => $v)
    // {
    // $item['display_options'][$k] = isset($_LANG['cfg_range'][$item['code']][$v]) ?
    // $_LANG['cfg_range'][$item['code']][$v] : $v;
    // }
    // }
    // $group_list[$pid]['vars'][] = $item;
    // }
    // }

    // }

    // return $group_list;
// }


}      
